package multithread.按序打印1114;

import java.util.concurrent.Semaphore;
class Foo {
    /**
     * 通过信号量
     */
    public Semaphore seam_first_two = new Semaphore(0);
    public Semaphore seam_two_second = new Semaphore(0);
    /**
     * 利用 CountDownLatch 计数
     */
//    private CountDownLatch second = new CountDownLatch(1);
//    private CountDownLatch third = new CountDownLatch(1);
    
    public Foo() {
        
    }

    public void first(Runnable printFirst) throws InterruptedException {
        printFirst.run();
        seam_first_two.release();
//        second.countDown();
    }

    public void second(Runnable printSecond) throws InterruptedException {
        seam_first_two.acquire();
//        second.await();
        printSecond.run();
        seam_two_second.release();
//        third.countDown();
    }

    public void third(Runnable printThird) throws InterruptedException {
        seam_two_second.acquire();
//        third.await();
        printThird.run();
    }
}